<?php
namespace Admin\Controller;
use Think\Controller;

class MemberdelController extends CommonController {
    public function index(){
        $data = I('get.');
        if(isset($data['bgtime'])){
            if($data['bgtime']==''){
                $data['btime']=strtotime('1971-01-01');
            }else{
                $data['btime']=strtotime($data['bgtime']);
            }
            if($data['endtime']==''){
                $data['etime']=time();
            }else{
                $data['etime']=strtotime($data['endtime']);
            }
            $where['create_time'] = array('between', array($data['btime'], $data['etime']));
            $sql_all = "where isdel='1' and create_time between ".$data['btime'].' and '.$data['etime'];
            
            if($data['nickname']!=''){
                $where['nickname'] = array('LIKE','%'.$data['nickname'].'%');
                $sql_all=$sql_all.' and nickname like "%'.$data['nickname'].'%" ';
            }
            $user_search = M('user')->where($where)->select();
            $this->assign('nickname',$data['nickname']);
            $this->assign('bgtime',$data['bgtime']);
            $this->assign('endtime',$data['endtime']);
            $sql = "select * from user ".$sql_all;
            $count = count(M('user')->query($sql));
            $this->page($count,$sql);
        }else{
            $user_all=M('user')->select();
            $sql = "select * from user where isdel='1' ";
            $count = count(M('user')->query($sql));
            $this->page($count,$sql);
        }
    }

    public function page($count,$sql){
        $Page = new \Think\Page($count,3);// 实例化分页类 
        $sql_user =$sql.' order by create_time limit '.$Page->firstRow.','.$Page->listRows;
        $user = M('user')->query($sql_user);
        /*$admin = M('auth_group_access t1')->join('left join auth_group t2 on t1.group_id=t2.id')->select(); */
        $show = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $this->assign('user',$user);
        $this->assign('count',$count);
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
    }

    public function recover(){
        $this->recoverOne('uid','user');
    }

    public function delAll(){
        $this->deleteAll('uid','user');
    }

    public function del(){
        //var_dump(I('post.'));exit;
        $this->delOne('uid','user');
    }
}

?>